using imitateMacQQ.WebApi.Domain.Request.utils;
using imitateMacQQ.WebApi.Domain.Token.wand.Token.Entity;
using imitateMacQQ.WebApi.Domain.Token.wand.Token.Interface;
using imitateMacQQ.WebApi.Domain.Token.wand.Token.letter;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace imitateMacQQ.WebApi.Api.Login_refresh;

[ApiController]
[Route("api/[controller]/[action]")]
public class LoginController : ControllerBase
{
    private readonly IGetTokenService _getTokenService;
    private readonly IGetAccessTokenUsedRefreshToken _getAccessToken;

    public LoginController(IGetTokenService getTokenService,
        IGetAccessTokenUsedRefreshToken getAccessTokenUsedRefreshToken)
    {
        _getTokenService = getTokenService;
        _getAccessToken = getAccessTokenUsedRefreshToken;
    }


    [HttpPost]
    public Request<LoginSuccessAccessTokenAndRefreshToken> Login(LetterFromUsersToBackstage dto)
    {
        return _getTokenService.RegisterGetToken(dto);
    }

    [Authorize]
    [HttpPost]
    public Request<LoginRefreshToken> RefreshState(LetterRefreshToken dto)
    {
        return _getAccessToken.GetAccessTokenUsedRefreshToken(dto);
    }
}